import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.util.Arrays;
import java.util.Scanner;

public class Array {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入1个整数：");
        //输入
        int num = input.nextInt();
        for (int i = 2; i < num; i++) {
            if (num % i == 0) {
                System.out.println("不是素数");
                break;
            }else {
                System.out.println("是素数");
            }
        }
    }
    public static void main18(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入两个整数：");
        //输入
        int x = input.nextInt();
        int y = input.nextInt();
        //计算最大值
        int max = x > y ? x : y;//存储最大值的变量
        System.out.println(max);//输入最大值
    }
    public static void main17(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入两个整数：");
        //输入
        int x = input.nextInt();
        int y = input.nextInt();
        //计算最大值
        int max = 0;//存储最大值的变量
        if (x > y) {
            max = x;
        }else {
            max = y;
        }
        System.out.println(max);//输入最大值
    }
    public static void main16(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入两个整数：");
        //输入
        int x = input.nextInt();
        int y = input.nextInt();
        //计算和
        int sum = x + y;
        System.out.println(sum);//输入两个整数和
    }
    public static void main15(String[] args) {
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();//输入
        if (a < 9) {//只有一位数的情况本身就是十位
            System.out.println(a);
        }else {
            System.out.println(a / 10);//除10求余数
        }
    }
    public static void main14(String[] args) {
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();//输入
        if (a < 9) {//只有一位数的情况本身就是个位
            System.out.println(a);
        }else {
            System.out.println(a % 10);//模10求余数
        }
    }
    public static void main13(String[] args) {
        Scanner input = new Scanner(System.in);
        //输入
        int a = input.nextInt();
        int b = input.nextInt();
        System.out.println("商：" + a / b);//商
        System.out.println("余数：" + a % b);//余数
    }
    public static void main12(String[] args) {
        System.out.println("Java是世界上最好的语言!");
    }
    /**
     * @project 二分查找
     **/
    public static int binarysearch(int[] array, int k) {
        int sz = array.length;//求数组长度
        int left = array[0];//左下标
        int right = sz - 1;//右下标
        while (left <= right) {
            int mid = (left + right) / 2;//中间下标
            if (array[mid] > k) {//要找的元素在左边
                right--;
            } else if (array[mid] < k) {//要找的元素在右边
                left++;
            } else {//找到了返回下标
                return mid - 1;//下标是从0开始的，每一个元素的下标都是 n-1
            }
        }
        return -1;
    }

    public static void main11(String[] args) {
        int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        //int k = 7;//查找的元素
        Scanner input = new Scanner(System.in);
        System.out.print("输入要查找的元素：");
        int k = input.nextInt();//输入要查找的元素
        int ret = binarysearch(array, k);
        /**
         * @rule 返回1说明找到了 - 返回-1说明没找到
         * @rule 输出找到元素的下标
         **/
        if (-1 == ret) {
            //找不到
            System.out.println("找不到，因为元素不存在");

        } else {
            System.out.println("找到了，下标是：" + array[ret]);
        }
    }

        public static void main10 (String[]args){
            int[] array1 = {1, 2, 3, 4, 5};

            int[] array2 = Arrays.copyOf(array1, array1.length);
            System.out.println(Arrays.toString(array1));
            System.out.println(Arrays.toString(array2));
        }
        public static void main9 (String[]args){
            int[] array1 = {1, 2, 3, 4, 5};//源空间
            int[] array2 = new int[array1.length];//目标空间
            for (int i = 0; i < array1.length; i++) {
                array2[i] = array1[i];
            }
            System.out.println(Arrays.toString(array1));
            System.out.println(Arrays.toString(array2));
        }
        /**
         * @project 模拟实现toString
         * **/
        public static String MyTostring ( int[] array){
            //判断数组是否是null
            if (null == array) {
                return null;
            }
            String ch = "[";//存储左边的括号
            for (int i = 0; i < array.length; i++) {
                ch += array[i];//将下标为i的元素拼接到ch里
                //判断是不是最后一个元素 - 最后一个元素后面没有逗号。
                if (i != array.length - 1) {//不是最后一个元素就加上一个逗号
                    ch += ",";
                }
            }
            //数组遍历完毕 - 逗号也添加完毕 - 只差右边的括号了
            ch += "]";
            return ch;
        }

        public static void main8 (String[]args){
            int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
            String ret = MyTostring(array);
            System.out.println(ret);
        }

        public static void main7 (String[]args){
            int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
            String ret = Arrays.toString(array);
            System.out.println(ret);
        }
        public static void func1 ( int[] arr){
            arr = new int[10];
        }

        public static void func2 ( int[] arr){
            arr[0] = 99;
        }

        public static void main6 (String[]args){
            int[] array = {1, 2, 3, 4};
            func1(array);
            System.out.println(Arrays.toString(array));
            func2(array);
            System.out.println(Arrays.toString(array));

        }
        public static void main5 (String[]args){
            int a = 1;
            int b = 2;
            int[] array = {1, 2, 3};
        }
        public static void main4 (String[]args){
            int[] arr = {10, 20, 30};
            String ret = Arrays.toString(arr);
            System.out.println(ret);
        }
        public static void main3 (String[]args){
            int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
            System.out.println(arr[9]);
        }
        public static void main2 (String[]args){
            int[] arr = {10, 20, 30};
            int len = arr.length;
            System.out.println(len);
        }
        public static void main1 (String[]args){
            int a = 10;
            int b = 20;
            int c = 30;
            //......
            //这个时候可以使用数组来减少繁琐的定义变量
            int[] ArrInt = {10, 20, 30};
            float[] ArrFloat = {12.2f, 12.3f, 12.4f};
            System.out.print(ArrInt[0] + " ");
            System.out.print(ArrInt[1] + " ");
            System.out.println(ArrInt[2] + " ");
            System.out.print(ArrFloat[0] + " ");
            System.out.print(ArrFloat[1] + " ");
            System.out.println(ArrFloat[2] + " ");
        }
    }